import { playMode } from 'common/js/config'
import { shuffle } from 'common/js/util'
import { mapGetters, mapMutations } from 'vuex'

export default {
    computed: {
        // 播放模式
        iconMode() {
            let rs = ''
            switch (this.mode) {
                case playMode.sequence:
                    rs = 'icon-sequence'
                    break
                case playMode.loop:
                    rs = 'icon-loop'
                    break
                case playMode.random:
                    rs = 'icon-random'
                    break
                default:
                    break
            }
            return rs
        },
        ...mapGetters([
            'sequenceList',
            'currentSong',
            'playList',
            'mode'
        ])
    },
    methods: {
        // 改变播放模式
        changeMode() {
            // 修改播放模式
            const mode = (this.mode + 1) % 3
            this.setPlayMode(mode)

            // 修改播放列表
            let list = []
            if (mode === playMode.random) {
                list = shuffle(this.sequenceList)
            } else {
                list = this.sequenceList
            }

            // 修改当前播放歌曲id
            this.resetCurrentIndex(list)

            this.setPlaylist(list)

            this.setToastMsg(this.toastMsgs[mode])
        },
        ...mapMutations({
            setPlaying: 'SET_PLAYING',
            setCurrentIndex: 'SET_CURRENT_INDEX',
            setPlayMode: 'SET_PLAY_MODE',
            setPlaylist: 'SET_PLAY_LIST'
        })
    }
}
